/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.gui.mvc.view.labels;

import org.testis.gui.mvc.utilities.*;
import org.testis.orm.labelhandler.LabelRefined;
import org.testis.utils.tree.DefaultMutableLabelNode;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 *
 * @author selcuk
 */
public class DefaultLabelNodeRenderer extends DefaultTreeCellRenderer {

    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value,
            boolean sel,
            boolean expanded,
            boolean leaf, int row,
            boolean hasFocus) {
        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
                row, hasFocus);
        DefaultMutableLabelNode lblNode = (DefaultMutableLabelNode) value;
        LabelRefined lblRefined = lblNode.getLabel();
        if(lblRefined != null){
            String imageName = "label.png";
            ImageIcon imageIcon = createImageIcon("images/testdesign/" + imageName);
            setIcon(imageIcon);
        } else {
            Icon imageIcon = super.getOpenIcon();
            setIcon(imageIcon);
        }
        return this;
    }

    public static ImageIcon createImageIcon(String path) {
        return ImageFactory.instance().createImageIcon(path);
    }
}
